<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "news_banner".
 *
 * @property integer $id
 * @property string $title
 * @property string $image
 * @property string $newsurl
 * @property integer $newsid
 * @property string $ptime
 * @property integer $status
 * @property integer $position
 * @property integer $sort
 * @property integer $userid
 * @property integer $ctime
 * @property integer $mtime
 */
class NewsBanner extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'news_banner';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title','image','newsurl','status','position'], 'required'],
            [['newsid', 'status', 'position', 'sort', 'userid', 'ctime', 'mtime'], 'integer'],
            [['ptime'], 'safe'],
            [['title', 'image', 'newsurl'], 'string', 'max' => 500],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Title',
            'image' => 'Image',
            'newsurl' => 'Newsurl',
            'newsid' => 'Newsid',
            'ptime' => 'Ptime',
            'status' => 'Status',
            'position' => 'Position',
            'sort' => 'Sort',
            'userid' => 'Userid',
            'ctime' => 'Ctime',
            'mtime' => 'Mtime',
        ];
    }

    public static function bannerNum(){
        $num = NewsBanner::find()->where(['status' => 0])->count();
        return $num;
    }

    public static function hasListBanner(){
        $num = NewsBanner::find()->where(['status' => 0,'position' => 1])->count();
        return $num;
    }
}
